﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace MobileBact
{
    public partial class SettingsPage : PhoneApplicationPage
    {
        public SettingsPage()
        {
            InitializeComponent();

            speedSlider.ValueChanged += speedSlider_ValueChanged;
            accelerationSlider.ValueChanged += accelerationSlider_ValueChanged;
            fagoSpeedSlider.ValueChanged += fagoSpeedSlider_ValueChanged;
            fagoAccelerationSlider.ValueChanged += fagoAccelerationSlider_ValueChanged;

            SolidColorBrush green = new SolidColorBrush(Colors.Green);
            speedLabel.Foreground = green;
            accelerationLabel.Foreground = green;
            speedTextBlock.Foreground = green;
            accelerationTextBlock.Foreground = green;

            SolidColorBrush red = new SolidColorBrush(Colors.Red);
            fagoSpeedLabel.Foreground = red;
            fagoAccelerationLabel.Foreground = red;
            fagoSpeedTextBlock.Foreground = red;
            fagoAccelerationTextBlock.Foreground = red;
        }

        protected Settings GetSettings()
        {
            return ((App.Current) as App).LastSettings;
        }

        void fagoAccelerationSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            double value = fagoAccelerationSlider.Value;
            GetSettings().FagoAcceleration = value;
            fagoAccelerationTextBlock.Text = value.ToString();
        }

        void fagoSpeedSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            double value = fagoSpeedSlider.Value;
            GetSettings().FagoInitialSpeedMagnitute = value;
            fagoSpeedTextBlock.Text = value.ToString();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Settings settings = (App.Current as App).LastSettings;
            this.speedSlider.Value = settings.InitialSpeedMagnitude;
            this.speedTextBlock.Text = settings.InitialSpeedMagnitude.ToString();
            this.fagoSpeedSlider.Value = settings.FagoInitialSpeedMagnitute;
            this.fagoSpeedTextBlock.Text = settings.FagoInitialSpeedMagnitute.ToString();

            this.accelerationSlider.Value = settings.Acceleration;
            this.accelerationTextBlock.Text = settings.Acceleration.ToString();
            this.fagoAccelerationSlider.Value = settings.FagoAcceleration;
            this.fagoAccelerationTextBlock.Text = settings.FagoAcceleration.ToString();
        }

        void accelerationSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Settings settings = (App.Current as App).LastSettings;
            settings.Acceleration = accelerationSlider.Value;
            this.accelerationTextBlock.Text = settings.Acceleration.ToString();
        }

        void speedSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Settings settings = (App.Current as App).LastSettings;
            settings.InitialSpeedMagnitude = speedSlider.Value;
            this.speedTextBlock.Text = settings.InitialSpeedMagnitude.ToString();
        }


    }
}